<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />





  <link rel="alternate" href="/atom.xml" title="青松的博客" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico?v=5.1.2" />






<meta property="og:type" content="website">
<meta property="og:title" content="青松的博客">
<meta property="og:url" content="http://www.codr.top/index.html">
<meta property="og:site_name" content="青松的博客">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="青松的博客">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://www.codr.top/"/>





  <title>青松的博客</title>
  














</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
   page-home 
 ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">青松的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">学习、记录、分享</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.codr.top/2019/01/目录/Java多线程编程核心技术-高洪岩-目录/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="qingsong">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="青松的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/01/目录/Java多线程编程核心技术-高洪岩-目录/" itemprop="url">Java多线程编程核心技术-高洪岩-目录</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-01-06T08:05:12+08:00">
                2019-01-06
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/目录/" itemprop="url" rel="index">
                    <span itemprop="name">目录</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2019/01/目录/Java多线程编程核心技术-高洪岩-目录/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2019/01/目录/Java多线程编程核心技术-高洪岩-目录/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2019/01/目录/Java多线程编程核心技术-高洪岩-目录/" class="leancloud_visitors" data-flag-title="Java多线程编程核心技术-高洪岩-目录">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  1,820
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  8
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div><div class="line">143</div><div class="line">144</div><div class="line">145</div><div class="line">146</div><div class="line">147</div><div class="line">148</div><div class="line">149</div><div class="line">150</div><div class="line">151</div><div class="line">152</div><div class="line">153</div><div class="line">154</div><div class="line">155</div><div class="line">156</div><div class="line">157</div><div class="line">158</div><div class="line">159</div><div class="line">160</div><div class="line">161</div><div class="line">162</div><div class="line">163</div><div class="line">164</div><div class="line">165</div><div class="line">166</div><div class="line">167</div><div class="line">168</div><div class="line">169</div><div class="line">170</div><div class="line">171</div><div class="line">172</div></pre></td><td class="code"><pre><div class="line">前 言</div><div class="line">第1章 Java多线程技能，</div><div class="line">    1.1 进程和多线程的概念及线程的优点</div><div class="line">    1.2 使用多线程</div><div class="line">        1.2.1 继承Thread类</div><div class="line">        1.2.2 实现Runnable接口</div><div class="line">        1.2.3 实例变量与线程安全</div><div class="line">        1.2.4 留意i——与System.out.println（）的异常</div><div class="line">    1.3 currentThread（）方法</div><div class="line">    1.4 isAlive（）方法</div><div class="line">    1.5 sleep（）方法</div><div class="line">    1.6 getId（）方法</div><div class="line">    1.7 停止线程</div><div class="line">        1.7.1 停止不了的线程</div><div class="line">        1.7.2 判断线程是否是停止状态</div><div class="line">        1.7.3 能停止的线程——异常法</div><div class="line">        1.7.4 在沉睡中停止</div><div class="line">        1.7.5 能停止的线程——暴力停止</div><div class="line">        1.7.6 方法stop（）与java.lang.ThreadDeath异常</div><div class="line">        1.7.7 释放锁的不良后果</div><div class="line">        1.7.8 使用return停止线程</div><div class="line">    1.8 暂停线程</div><div class="line">        1.8.1 suspend与resume方法的使用</div><div class="line">        1.8.2 suspend与resume方法的缺点——独占</div><div class="line">        1.8.3 suspend与resume方法的缺点——不同步</div><div class="line">    1.9 yield方法</div><div class="line">    1.10 线程的优先级</div><div class="line">        1.10.1 线程优先级的继承特性</div><div class="line">        1.10.2 优先级具有规则性</div><div class="line">        1.10.3 优先级具有随机性</div><div class="line">        1.10.4 看谁运行得快</div><div class="line">    1.11 守护线程</div><div class="line">    1.12 本章小结</div><div class="line"></div><div class="line">第2章 对象及变量的并发访问</div><div class="line">    2.1 synchronized同步方法</div><div class="line">        2.1.1 方法内的变量为线程安全</div><div class="line">        2.1.2 实例变量非线程安全</div><div class="line">        2.1.3 多个对象多个锁</div><div class="line">        2.1.4 synchronized方法与锁对象</div><div class="line">        2.1.5 脏读</div><div class="line">        2.1.6 synchronized锁重入</div><div class="line">        2.1.7 出现异常，锁自动释放</div><div class="line">        2.1.8 同步不具有继承性</div><div class="line">    2.2 synchronized同步语句块</div><div class="line">        2.2.1 synchronized方法的弊端</div><div class="line">        2.2.2 synchronized同步代码块的使用</div><div class="line">        2.2.3 用同步代码块解决同步方法的弊端</div><div class="line">        2.2.4 一半异步，一半同步</div><div class="line">        2.2.5 synchronized代码块间的同步性</div><div class="line">        2.2.6 验证同步synchronized（this）代码块是锁定当前对象的</div><div class="line">        2.2.7 将任意对象作为对象监视器</div><div class="line">        2.2.8 细化验证3个结论</div><div class="line">        2.2.9 静态同步synchronized方法与synchronized（class）代码块</div><div class="line">        2.2.10 数据类型String的常量池特性</div><div class="line">        2.2.11 同步synchronized方法无限等待与解决</div><div class="line">        2.2.12 多线程的死锁</div><div class="line">        2.2.13 内置类与静态内置类</div><div class="line">        2.2.14 内置类与同步：实验1</div><div class="line">        2.2.15 内置类与同步：实验2</div><div class="line">        2.2.16 锁对象的改变</div><div class="line">    2.3 volatile关键字</div><div class="line">        2.3.1 关键字volatile与死循环</div><div class="line">        2.3.2 解决同步死循环</div><div class="line">        2.3.3 解决异步死循环</div><div class="line">        2.3.4 volatile非原子的特性</div><div class="line">        2.3.5 使用原子类进行i++操作</div><div class="line">        2.3.6 原子类也并不完全安全</div><div class="line">        2.3.7 synchronized代码块有volatile同步的功能</div><div class="line">    2.4 本章总结</div><div class="line"></div><div class="line">第3章 线程间通信</div><div class="line">    3.1 等待/通知机制</div><div class="line">        3.1.1 不使用等待/通知机制实现线程间通信</div><div class="line">        3.1.2 什么是等待/通知机制</div><div class="line">        3.1.3 等待/通知机制的实现</div><div class="line">        3.1.4 方法wait（）锁释放与notify（）锁不释放</div><div class="line">        3.1.5 当interrupt方法遇到wait方法</div><div class="line">        3.1.6 只通知一个线程</div><div class="line">        3.1.7 唤醒所有线程</div><div class="line">        3.1.8 方法wait（long）的使用</div><div class="line">        3.1.9 通知过早</div><div class="line">        3.1.10 等待wait的条件发生变化</div><div class="line">        3.1.11 生产者/消费者模式实现</div><div class="line">        3.1.12 通过管道进行线程间通信：字节流</div><div class="line">        3.1.13 通过管道进行线程间通信：字符流</div><div class="line">        3.1.14 实战：等待/通知之交叉备份</div><div class="line">    3.2 方法join的使用</div><div class="line">        3.2.1 学习方法join前的铺垫</div><div class="line">        3.2.2 用join（）方法来解决</div><div class="line">        3.2.3 方法join与异常</div><div class="line">        3.2.4 方法join（long）的使用</div><div class="line">        3.2.5 方法join（long）与sleep（long）的区别</div><div class="line">        3.2.6 方法join（）后面的代码提前运行：出现意外</div><div class="line">        3.2.7 方法join（）后面的代码提前运行：解释意外</div><div class="line">    3.3 类ThreadLocal的使用</div><div class="line">        3.3.1 方法get（）与null</div><div class="line">        3.3.2 验证线程变量的隔离性</div><div class="line">        3.3.3 解决get（）返回null问题</div><div class="line">        3.3.4 再次验证线程变量的隔离性</div><div class="line">    3.4 类InheritableThreadLocal的使用</div><div class="line">        3.4.1 值继承</div><div class="line">        3.4.2 值继承再修改</div><div class="line">    3.5 本章总结</div><div class="line"></div><div class="line">第4章 Lock的使用</div><div class="line">    4.1 使用ReentrantLock类</div><div class="line">        4.1.1 使用ReentrantLock实现同步：测试1</div><div class="line">        4.1.2 使用ReentrantLock实现同步：测试2</div><div class="line">        4.1.3 使用Condition实现等待/通知错误用法与解决</div><div class="line">        4.1.4 正确使用Condition实现等待/通知</div><div class="line">        4.1.5 使用多个Condition实现通知部分线程：错误用法</div><div class="line">        4.1.6 使用多个Condition实现通知部分线程：正确用法</div><div class="line">        4.1.7 实现生产者/消费者模式：一对一交替打印</div><div class="line">        4.1.8 实现生产者/消费者模式：多对多交替打印</div><div class="line">        4.1.9 公平锁与非公平锁</div><div class="line">        4.1.10 方法getHoldCount（）、getQueueLength（）和getWaitQueueLength（）的测试</div><div class="line">        4.1.11 方法hasQueuedThread（）、hasQueuedThreads（）和hasWaiters（）的测试</div><div class="line">        4.1.12 方法isFair（）、isHeldByCurrentThread（）和isLocked（）的测试</div><div class="line">        4.1.13 方法lockInterruptibly（）、tryLock（）和tryLock（long timeout，TimeUnit unit）的测试</div><div class="line">        4.1.14 方法awaitUninterruptibly（）的使用</div><div class="line">        4.1.15 方法awaitUntil（）的使用</div><div class="line">        4.1.16 使用Condition实现顺序执行</div><div class="line">    4.2 使用ReentrantReadWriteLock类</div><div class="line">        4.2.1 类ReentrantReadWriteLock的使用：读读共享</div><div class="line">        4.2.2 类ReentrantReadWriteLock的使用：写写互斥</div><div class="line">        4.2.3 类ReentrantReadWriteLock的使用：读写互斥</div><div class="line">        4.2.4 类ReentrantReadWriteLock的使用：写读互斥</div><div class="line">    4.3 本章总结</div><div class="line"></div><div class="line">第5章 定时器Timer</div><div class="line">    5.1 定时器Timer的使用</div><div class="line">        5.1.1 方法schedule（TimerTask task， Date time）的测试</div><div class="line">        5.1.2 方法schedule（TimerTask task， Date firstTime， long period）的测试</div><div class="line">        5.1.3 方法schedule（TimerTask task， long delay）的测试</div><div class="line">        5.1.4 方法schedule（TimerTask task， long delay， long period）的测试</div><div class="line">        5.1.5 方法scheduleAtFixedRate（TimerTask task， Date firstTime， long period）的测试</div><div class="line">    5.2 本章总结</div><div class="line"></div><div class="line">第6章 单例模式与多线程</div><div class="line">    6.1 立即加载/&quot;饿汉模式&quot;</div><div class="line">    6.2 延迟加载/&quot;懒汉模式&quot;</div><div class="line">    6.3 使用静态内置类实现单例模式</div><div class="line">    6.4 序列化与反序列化的单例模式实现</div><div class="line">    6.5 使用static代码块实现单例模式</div><div class="line">    6.6 使用enum枚举数据类型实现单例模式</div><div class="line">    6.7 完善使用enum枚举实现单例模式</div><div class="line">    6.8 本章总结</div><div class="line"></div><div class="line">第7章 拾遗增补</div><div class="line">    7.1 线程的状态</div><div class="line">        7.1.1 验证NEW、RUNNABLE和TERMINATED</div><div class="line">        7.1.2 验证TIMED_WAITING</div><div class="line">        7.1.3 验证BLOCKED</div><div class="line">        7.1.4 验证WAITING</div><div class="line">    7.2 线程组</div><div class="line">        7.2.1 线程对象关联线程组：1级关联</div><div class="line">        7.2.2 线程对象关联线程组：多级关联</div><div class="line">        7.2.3 线程组自动归属特性</div><div class="line">        7.2.4 获取根线程组</div><div class="line">        7.2.5 线程组里加线程组</div><div class="line">        7.2.6 组内的线程批量停止</div><div class="line">        7.2.7 递归与非递归取得组内对象</div><div class="line">    7.3 使线程具有有序性</div><div class="line">    7.4 SimpleDateFormat非线程安全</div><div class="line">        7.4.1 出现异常</div><div class="line">        7.4.2 解决异常方法1</div><div class="line">        7.4.3 解决异常方法2</div><div class="line">    7.5 线程中出现异常的处理</div><div class="line">    7.6 线程组内处理异常</div><div class="line">    7.7 线程异常处理的传递</div><div class="line">    7.8 本章总结</div></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.codr.top/2019/01/目录/实战Java高并发程序设计-葛一鸣-目录/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="qingsong">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="青松的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/01/目录/实战Java高并发程序设计-葛一鸣-目录/" itemprop="url">实战Java高并发程序设计-葛一鸣-目录</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-01-06T08:02:45+08:00">
                2019-01-06
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/目录/" itemprop="url" rel="index">
                    <span itemprop="name">目录</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2019/01/目录/实战Java高并发程序设计-葛一鸣-目录/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2019/01/目录/实战Java高并发程序设计-葛一鸣-目录/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2019/01/目录/实战Java高并发程序设计-葛一鸣-目录/" class="leancloud_visitors" data-flag-title="实战Java高并发程序设计-葛一鸣-目录">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  1,867
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  8
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div><div class="line">143</div><div class="line">144</div><div class="line">145</div><div class="line">146</div><div class="line">147</div><div class="line">148</div><div class="line">149</div><div class="line">150</div><div class="line">151</div><div class="line">152</div><div class="line">153</div><div class="line">154</div><div class="line">155</div><div class="line">156</div><div class="line">157</div><div class="line">158</div><div class="line">159</div><div class="line">160</div><div class="line">161</div><div class="line">162</div><div class="line">163</div><div class="line">164</div><div class="line">165</div><div class="line">166</div><div class="line">167</div><div class="line">168</div><div class="line">169</div><div class="line">170</div><div class="line">171</div><div class="line">172</div><div class="line">173</div><div class="line">174</div><div class="line">175</div><div class="line">176</div><div class="line">177</div><div class="line">178</div><div class="line">179</div><div class="line">180</div><div class="line">181</div><div class="line">182</div><div class="line">183</div><div class="line">184</div><div class="line">185</div><div class="line">186</div><div class="line">187</div></pre></td><td class="code"><pre><div class="line">第1章走入并行世界 </div><div class="line">    1.1何去何从的并行计算 </div><div class="line">        1.1.1忘掉那该死的并行 </div><div class="line">        1.1.2可怕的现实：摩尔定律的失效 </div><div class="line">        1.1.3柳暗花明：不断地前进 </div><div class="line">        1.1.4光明或是黑暗 </div><div class="line">    1.2你必须知道的几个概念 </div><div class="line">        1.2.1同步（Synchronous）和异步（Asynchronous） </div><div class="line">        1.2.2并发（Concurrency）和并行（Parallelism） </div><div class="line">        1.2.3临界区 </div><div class="line">        1.2.4阻塞（Blocking）和非阻塞（Non—Blocking） </div><div class="line">        1.2.5死锁（Deadlock）、饥饿（Starvation）和活锁（Livelock） </div><div class="line">    1.3并发级别 </div><div class="line">        1.3.1阻塞（Blocking） </div><div class="line">        1.3.2无饥饿（Starvation—Free） </div><div class="line">        1.3.3无障碍（Obstruction—Free） </div><div class="line">        1.3.4无锁（Lock—Free） </div><div class="line">        1.3.5无等待（Wait—Free） </div><div class="line">    1.4有关并行的两个重要定律 </div><div class="line">        1.4.1Amdahl定律 </div><div class="line">        1.4.2Gustafson定律 </div><div class="line">        1.4.3Amdahl定律和Gustafson定律是否相互矛盾 </div><div class="line">    1.5回到Java：JMM </div><div class="line">        1.5.1原子性（Atomicity） </div><div class="line">        1.5.2可见性（Visibility） </div><div class="line">        1.5.3有序性（Ordering） </div><div class="line">        1.5.4哪些指令不能重排：Happen—Before规则 </div><div class="line">    1.6参考文献 </div><div class="line">第2章Java并行程序基础 </div><div class="line">    2.1有关线程你必须知道的事 </div><div class="line">    2.2初始线程：线程的基本操作 </div><div class="line">        2.2.1新建线程 </div><div class="line">        2.2.2终止线程 </div><div class="line">        2.2.3线程中断 </div><div class="line">        2.2.4等待（wait）和通知（notify） </div><div class="line">        2.2.5挂起（suspend）和继续执行（resume）线程 </div><div class="line">        2.2.6等待线程结束（join）和谦让（yield） </div><div class="line">    2.3volatile与Java内存模型（JMM） </div><div class="line">    2.4分门别类的管理：线程组 </div><div class="line">    2.5驻守后台：守护线程（Daemon） </div><div class="line">    2.6先干重要的事：线程优先级 </div><div class="line">    2.7线程安全的概念与synchronized </div><div class="line">    2.8程序中的幽灵：隐蔽的错误 </div><div class="line">        2.8.1无提示的错误案例 </div><div class="line">        2.8.2并发下的ArrayList </div><div class="line">        2.8.3并发下诡异的HashMap </div><div class="line">        2.8.4初学者常见问题：错误的加锁 </div><div class="line">    2.9参考文献 </div><div class="line">第3章JDK并发包 </div><div class="line">    3.1多线程的团队协作：同步控制 </div><div class="line">        3.1.1synchronized的功能扩展：重入锁 </div><div class="line">        3.1.2重入锁的好搭档：Condition条件 </div><div class="line">        3.1.3允许多个线程同时访问：信号量（Semaphore） </div><div class="line">        3.1.4ReadWriteLock读写锁 </div><div class="line">        3.1.5倒计时器：CountDownLatch </div><div class="line">        3.1.6循环栅栏：CyclicBarrier </div><div class="line">        3.1.7线程阻塞工具类：LockSupport </div><div class="line">    3.2线程复用：线程池 </div><div class="line">        3.2.1什么是线程池 </div><div class="line">        3.2.2不要重复发明轮子：JDK对线程池的支持 </div><div class="line">        3.2.3刨根究底：核心线程池的内部实现 </div><div class="line">        3.2.4超负载了怎么办：拒绝策略 </div><div class="line">        3.2.5自定义线程创建：ThreadFactory </div><div class="line">        3.2.6我的应用我做主：扩展线程池 </div><div class="line">        3.2.7合理的选择：优化线程池线程数量 </div><div class="line">        3.2.8堆栈去哪里了：在线程池中寻找堆栈 </div><div class="line">        3.2.9分而治之：Fork／Join框架 </div><div class="line">    3.3不要重复发明轮子：JDK的并发容器 </div><div class="line">        3.3.1超好用的工具类：并发集合简介 </div><div class="line">        3.3.2线程安全的HashMap </div><div class="line">        3.3.3有关List的线程安全 </div><div class="line">        3.3.4高效读写的队列：深度剖析ConcurrentLinkedQueue </div><div class="line">        3.3.5高效读取：不变模式下的CopyOnWriteArrayList </div><div class="line">        3.3.6数据共享通道：BlockingQueue </div><div class="line">        3.3.7随机数据结构：跳表（SkipList） </div><div class="line">    3.4参考资料 </div><div class="line">第4章锁的优化及注意事项 </div><div class="line">    4.1有助于提高“锁”性能的几点建议 </div><div class="line">        4.1.1减小锁持有时间 </div><div class="line">        4.1.2减小锁粒度 </div><div class="line">        4.1.3读写分离锁来替换独占锁 </div><div class="line">        4.1.4锁分离 </div><div class="line">        4.1.5锁粗化 </div><div class="line">    4.2Java虚拟机对锁优化所做的努力 </div><div class="line">        4.2.1锁偏向 </div><div class="line">        4.2.2轻量级锁 </div><div class="line">        4.2.3自旋锁 </div><div class="line">        4.2.4锁消除 </div><div class="line">    4.3人手一支笔：ThreadLocal </div><div class="line">        4.3.1ThreadLocal的简单使用 </div><div class="line">        4.3.2ThreadLocal的实现原理 </div><div class="line">        4.3.3对性能有何帮助 </div><div class="line">    4.4无锁 </div><div class="line">        4.4.1与众不同的并发策略：比较交换（CAS） </div><div class="line">        4.4.2无锁的线程安全整数：AtomicInteger </div><div class="line">        4.4.3Java中的指针：Unsafe类 </div><div class="line">        4.4.4无锁的对象引用：AtomicReference </div><div class="line">        4.4.5带有时间戳的对象引用：AtomicStampedReference </div><div class="line">        4.4.6数组也能无锁：AtomicIntegerArray </div><div class="line">        4.4.7让普通变量也享受原子操作：AtomicIntegerFieldUpdater </div><div class="line">        4.4.8挑战无锁算法：无锁的Vector实现 </div><div class="line">        4.4.9让线程之间互相帮助：细看SynchronousQueue的实现 </div><div class="line">    4.5有关死锁的问题 </div><div class="line">    4.6参考文献 </div><div class="line">第5章并行模式与算法 </div><div class="line">    5.1探讨单例模式 </div><div class="line">    5.2不变模式 </div><div class="line">    5.3生产者—消费者模式 </div><div class="line">    5.4高性能的生产者—消费者：无锁的实现 </div><div class="line">        5.4.1无锁的缓存框架：Disruptor </div><div class="line">        5.4.2用Disruptor实现生产者—消费者案例 </div><div class="line">        5.4.3提高消费者的响应时间：选择合适的策略 </div><div class="line">        5.4.4CPUCache的优化：解决伪共享问题 </div><div class="line">    5.5Future模式 </div><div class="line">        5.5.1Future模式的主要角色 </div><div class="line">        5.5.2Future模式的简单实现 </div><div class="line">        5.5.3JDK中的Future模式 </div><div class="line">    5.6并行流水线 </div><div class="line">    5.7并行搜索 </div><div class="line">    5.8并行排序 </div><div class="line">        5.8.1分离数据相关性：奇偶交换排序 </div><div class="line">        5.8.2改进的插入排序：希尔排序 </div><div class="line">    5.9并行算法：矩阵乘法 </div><div class="line">    5.10准备好了再通知我：网络NIO </div><div class="line">        5.10.1基于Socket的服务端的多线程模式 </div><div class="line">        5.10.2使用NIO进行网络编程 </div><div class="line">        5.10.3使用NIO来实现客户端 </div><div class="line">    5.11读完了再通知我：AIO </div><div class="line">        5.11.1AIOEchoServer的实现 </div><div class="line">        5.11.2AIOEcho客户端实现 </div><div class="line">    5.12参考文献 </div><div class="line">第6章Java8与并发 </div><div class="line">    6.1Java8的函数式编程简介 </div><div class="line">        6.1.1函数作为一等公民 </div><div class="line">        6.1.2无副作用 </div><div class="line">        6.1.3申明式的（Declarative） </div><div class="line">        6.1.4不变的对象 </div><div class="line">        6.1.5易于并行 </div><div class="line">        6.1.6更少的代码 </div><div class="line">    6.2函数式编程基础 </div><div class="line">        6.2.1FunctionalInterface注释 </div><div class="line">        6.2.2接口默认方法 </div><div class="line">        6.2.3lambda表达式 </div><div class="line">        6.2.4方法引用 </div><div class="line">    6.3一步一步走入函数式编程 </div><div class="line">    6.4并行流与并行排序 </div><div class="line">        6.4.1使用并行流过滤数据 </div><div class="line">        6.4.2从集合得到并行流 </div><div class="line">        6.4.3并行排序 </div><div class="line">    6.5增强的Future：CompletableFuture </div><div class="line">        6.5.1完成了就通知我 </div><div class="line">        6.5.2异步执行任务 </div><div class="line">        6.5.3流式调用 </div><div class="line">        6.5.4CompletableFuture中的异常处理 </div><div class="line">        6.5.5组合多个CompletableFuture </div><div class="line">    6.6读写锁的改进：StampedLock </div><div class="line">        6.6.1StampedLock使用示例 </div><div class="line">        6.6.2StampedLock的小陷阱 </div><div class="line">        6.6.3有关StampedLock的实现思想 </div><div class="line">    6.7原子类的增强 </div><div class="line">        6.7.1更快的原子类：LongAdder </div><div class="line">        6.7.2LongAdder的功能增强版：LongAccumulator </div><div class="line">    6.8参考文献 </div><div class="line">第7章使用Akka构建高并发程序 </div><div class="line">    7.1新并发模型：Actor </div><div class="line">    7.2Akka之HelloWorld </div><div class="line">    7.3有关消息投递的一些说明 </div><div class="line">    7.4Actor的生命周期 </div><div class="line">    7.5监督策略 </div><div class="line">    7.6选择Actor </div><div class="line">    7.7消息收件箱（Inbox） </div><div class="line">    7.8消息路由 </div><div class="line">    7.9Actor的内置状态转换 </div><div class="line">    7.10询问模式：Actor中的Future </div><div class="line">    7.11多个Actor同时修改数据：Agent </div><div class="line">    7.12像数据库一样操作内存数据：软件事务内存 </div><div class="line">    7.13一个有趣的例子：并发粒子群的实现 </div><div class="line">        7.13.1什么是粒子群算法 </div><div class="line">        7.13.2粒子群算法的计算过程 </div><div class="line">        7.13.3粒子群算法能做什么 </div><div class="line">        7.13.4使用Akka实现粒子群 </div><div class="line">    7.14参考文献 </div><div class="line">第8章并行程序调试 </div><div class="line">    8.1准备实验样本 </div><div class="line">    8.2正式起航 </div><div class="line">    8.3挂起整个虚拟机 </div><div class="line">    8.4调试进入ArrayList内部</div></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.codr.top/2019/01/Java/java中HashMap源码笔记/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="qingsong">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="青松的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/01/Java/java中HashMap源码笔记/" itemprop="url">java中HashMap源码笔记</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-01-01T09:33:24+08:00">
                2019-01-01
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/java/" itemprop="url" rel="index">
                    <span itemprop="name">java</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2019/01/Java/java中HashMap源码笔记/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2019/01/Java/java中HashMap源码笔记/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2019/01/Java/java中HashMap源码笔记/" class="leancloud_visitors" data-flag-title="java中HashMap源码笔记">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  1,223
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  5
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="HashMap概述"><a href="#HashMap概述" class="headerlink" title="HashMap概述"></a>HashMap概述</h2><p>HashMap基于哈希表的 Map 接口的实现。并允许使用 null 值和 null 键。（除了不同步和允许使用 null 之外，HashMap 类与 Hashtable 大致相同。）<br>HashMap的数据结构使用数组和链表来实现对数据的存储，jdk1.8之后链表节点达到8之后转为红黑树。默认初始化容量为16（DEFAULT_INITIAL_CAPACITY = 1 &lt;&lt; 4; // aka 16），扩容因子0.75（DEFAULT_LOAD_FACTOR = 0.75f），树化链表值是8（TREEIFY_THRESHOLD = 8）。<br>HashMap为线程不安全，多线程操作会导致其死循环。</p>
<h2 id="数组-链表数据结构"><a href="#数组-链表数据结构" class="headerlink" title="数组+链表数据结构"></a>数组+链表数据结构</h2><p>HashMap的底层主要是基于数组和链表来实现的，它之所以有相当快的查询速度主要是因为它是通过计算散列码来决定存储的位置。如果存储的对象对多了，就有可能不同的对象所算出来的hash值是相同的，这就出现了所谓的hash冲突。解决hash冲突的方法有很多，HashMap底层是通过链表来解决hash冲突的。<br>数组的特点是：寻址容易，插入和删除困难。<br>链表的特点是：寻址困难，插入和删除容易。</p>
<p><img src="http://ww1.sinaimg.cn/large/99c92116ly1fyxs8t9ao1j20f10co75l.jpg" alt=""></p>
<h2 id="put插入方法"><a href="#put插入方法" class="headerlink" title="put插入方法"></a>put插入方法</h2><p>put数据过程</p>
<ol>
<li>key计算hash值</li>
<li>找位置，根据hash值取模找对应的数组中位置，（取模操作(n - 1) &amp; hash，n为数组的长度，相当于hash%n，位运算效率更高 ）</li>
<li>放入数据，如果为空放入数组，如果有hash碰撞，放入链表中，如果链表长度超过8，转化为红黑树</li>
<li>判断大小是否需要扩容</li>
</ol>
<p>先把key做下hash值计算：hash(key)<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">public V put(K key, V value) &#123;</div><div class="line">    return putVal(hash(key), key, value, false, true);</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>根据hash值判断放入数组链表相应位置中，<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div></pre></td><td class="code"><pre><div class="line">/**</div><div class="line"> * Implements Map.put and related methods</div><div class="line"> *</div><div class="line"> * @param hash hash for key</div><div class="line"> * @param key the key</div><div class="line"> * @param value the value to put</div><div class="line"> * @param onlyIfAbsent if true, don&apos;t change existing value</div><div class="line"> * @param evict if false, the table is in creation mode.</div><div class="line"> * @return previous value, or null if none</div><div class="line"> */</div><div class="line">final V putVal(int hash, K key, V value, boolean onlyIfAbsent,</div><div class="line">                   boolean evict) &#123;</div><div class="line">        // tab 数组，p指向节点， n数组长度，i取模索引位置</div><div class="line">        Node&lt;K,V&gt;[] tab; Node&lt;K,V&gt; p; int n, i;</div><div class="line">        // 数组没有创建初始化数组</div><div class="line">        if ((tab = table) == null || (n = tab.length) == 0)</div><div class="line">            n = (tab = resize()).length;</div><div class="line">        // 找放入的位置</div><div class="line">        // 1. 如果数组hash对应索引元素为空，创建数据赋值</div><div class="line">        if ((p = tab[i = (n - 1) &amp; hash]) == null)</div><div class="line">            tab[i] = newNode(hash, key, value, null);</div><div class="line">        else &#123;</div><div class="line">            Node&lt;K,V&gt; e; K k;</div><div class="line">            // 2. 如果和第一个节点hash值相同，key值相同，已存在</div><div class="line">            if (p.hash == hash &amp;&amp;</div><div class="line">                ((k = p.key) == key || (key != null &amp;&amp; key.equals(k))))</div><div class="line">                e = p;</div><div class="line">            // 3. 如果是红黑树节点，放入树节点</div><div class="line">            else if (p instanceof TreeNode)</div><div class="line">                e = ((TreeNode&lt;K,V&gt;)p).putTreeVal(this, tab, hash, key, value);</div><div class="line">            else &#123;</div><div class="line">            // 4. hash冲突，放到链表最后一个节点，或者转换为树 </div><div class="line">                for (int binCount = 0; ; ++binCount) &#123;</div><div class="line">                    if ((e = p.next) == null) &#123;</div><div class="line">                        p.next = newNode(hash, key, value, null);</div><div class="line">                        if (binCount &gt;= TREEIFY_THRESHOLD - 1) // -1 for 1st</div><div class="line">                            treeifyBin(tab, hash);</div><div class="line">                        break;</div><div class="line">                    &#125;</div><div class="line">                    if (e.hash == hash &amp;&amp;</div><div class="line">                        ((k = e.key) == key || (key != null &amp;&amp; key.equals(k))))</div><div class="line">                        break;</div><div class="line">                    p = e;</div><div class="line">                &#125;</div><div class="line">            &#125;</div><div class="line">            // 如果已经存在，则替换为新value</div><div class="line">            if (e != null) &#123; // existing mapping for key</div><div class="line">                V oldValue = e.value;</div><div class="line">                if (!onlyIfAbsent || oldValue == null)</div><div class="line">                    e.value = value;</div><div class="line">                afterNodeAccess(e);</div><div class="line">                return oldValue;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">        ++modCount;</div><div class="line">        // 判断大小是否超过阀值</div><div class="line">        if (++size &gt; threshold)</div><div class="line">            resize();</div><div class="line">        afterNodeInsertion(evict);</div><div class="line">        return null;</div><div class="line">    &#125;</div></pre></td></tr></table></figure></p>
<h2 id="get查询方法"><a href="#get查询方法" class="headerlink" title="get查询方法"></a>get查询方法</h2><p>get数据过程</p>
<ol>
<li>key计算hash值</li>
<li>找位置，如果第一key值相同，直接返回，不相同遍历链表中数据</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">public V get(Object key) &#123;</div><div class="line">    Node&lt;K,V&gt; e;</div><div class="line">    return (e = getNode(hash(key), key)) == null ? null : e.value;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div></pre></td><td class="code"><pre><div class="line">/**</div><div class="line"> * Implements Map.get and related methods</div><div class="line"> *</div><div class="line"> * @param hash hash for key</div><div class="line"> * @param key the key</div><div class="line"> * @return the node, or null if none</div><div class="line"> */</div><div class="line">final Node&lt;K,V&gt; getNode(int hash, Object key) &#123;</div><div class="line">    Node&lt;K,V&gt;[] tab; Node&lt;K,V&gt; first, e; int n; K k;</div><div class="line">    // (n - 1) &amp; hash 就是取模定位数组的索引</div><div class="line">    if ((tab = table) != null &amp;&amp; (n = tab.length) &gt; 0 &amp;&amp;</div><div class="line">        (first = tab[(n - 1) &amp; hash]) != null) &#123;</div><div class="line">        if (first.hash == hash &amp;&amp; // always check first node</div><div class="line">            ((k = first.key) == key || (key != null &amp;&amp; key.equals(k))))</div><div class="line">            // 数组中找到，返回</div><div class="line">            return first;</div><div class="line">        // 找链表中数据</div><div class="line">        if ((e = first.next) != null) &#123;</div><div class="line">            if (first instanceof TreeNode)</div><div class="line">            // 递归树查找</div><div class="line">                return ((TreeNode&lt;K,V&gt;)first).getTreeNode(hash, key);</div><div class="line">            do &#123;</div><div class="line">            // 遍历链表</div><div class="line">                if (e.hash == hash &amp;&amp;</div><div class="line">                    ((k = e.key) == key || (key != null &amp;&amp; key.equals(k))))</div><div class="line">                    return e;</div><div class="line">            &#125; while ((e = e.next) != null);</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">    return null;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="数组长度为什么总是设定为-2-的-N-次方？"><a href="#数组长度为什么总是设定为-2-的-N-次方？" class="headerlink" title="数组长度为什么总是设定为 2 的 N 次方？"></a>数组长度为什么总是设定为 2 的 N 次方？</h2><ol>
<li>取模快。<br>其实就是上面为什么快的原因：位与取模比 % 取模要快的多。</li>
<li>分散平均，减少碰撞。<br>这个是主要原因。<br>如果二进制某位包含 0，则此位置上的数据不同对应的 hash 却是相同，碰撞发生，而 (2^x - 1) 的二进制是 0111111…，分散非常平均，碰撞也是最少的。</li>
</ol>
<h2 id="解决hash冲突的办法"><a href="#解决hash冲突的办法" class="headerlink" title="解决hash冲突的办法"></a>解决hash冲突的办法</h2><ol>
<li>开放定址法（线性探测再散列，二次探测再散列，伪随机探测再散列）</li>
<li>再哈希法</li>
<li>链地址法</li>
<li>建立一个公共溢出区</li>
</ol>
<p>hashmap的解决办法就是采用的链地址法</p>
<h2 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h2><p><a href="https://blog.csdn.net/fighterandknight/article/details/61624150" target="_blank" rel="external">https://blog.csdn.net/fighterandknight/article/details/61624150</a><br><a href="http://jayfeng.com/2016/12/28/%E7%90%86%E8%A7%A3HashMap/" target="_blank" rel="external">http://jayfeng.com/2016/12/28/%E7%90%86%E8%A7%A3HashMap/</a></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.codr.top/2018/07/JVM/jvm方法区内存溢出/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="qingsong">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="青松的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/07/JVM/jvm方法区内存溢出/" itemprop="url">jvm方法区内存溢出</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-07-11T10:24:45+08:00">
                2018-07-11
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/JVM/" itemprop="url" rel="index">
                    <span itemprop="name">JVM</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/07/JVM/jvm方法区内存溢出/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2018/07/JVM/jvm方法区内存溢出/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2018/07/JVM/jvm方法区内存溢出/" class="leancloud_visitors" data-flag-title="jvm方法区内存溢出">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  156
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  1
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>java.lang.OutOfMemoryError: PermGen space</p>
<ul>
<li>jps查看java程序pid</li>
<li>保存heap：jmap -dump:format=b,file=heap.hprof pid，之后使用java自带工具jvisualvm分析数据</li>
<li>top查看cpu占用情况</li>
<li>top -H -p pid查看该进程具体线程情况 或者ps -mp pid -o THREAD,did,time</li>
<li>查看问题线程堆栈 ，查看该线程的堆栈情况，先将线程id转为16进制，使用printf “%x\n” tid命令进行转换，再使用jstack命令打印线程堆栈信息，命令格式：jstack pid |grep tid -A 30</li>
<li>jstat -gcutil pid 2000 10 命令查看进程的内存情况</li>
<li>jstack命令查看进程的堆栈情况</li>
</ul>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.codr.top/2018/07/spring家族/SpringBoot和redis实现session共享/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="qingsong">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="青松的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/07/spring家族/SpringBoot和redis实现session共享/" itemprop="url">SpringBoot和redis实现session共享</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-07-05T18:31:40+08:00">
                2018-07-05
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/SpringBoot/" itemprop="url" rel="index">
                    <span itemprop="name">SpringBoot</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/07/spring家族/SpringBoot和redis实现session共享/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2018/07/spring家族/SpringBoot和redis实现session共享/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2018/07/spring家族/SpringBoot和redis实现session共享/" class="leancloud_visitors" data-flag-title="SpringBoot和redis实现session共享">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  143
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  1
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <ol>
<li><p>添加@EnableRedisHttpSession来开启spring session支持</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">@Configuration  </div><div class="line">@EnableRedisHttpSession  </div><div class="line">public class RedisSessionConfig &#123;  </div><div class="line">&#125;</div></pre></td></tr></table></figure>
</li>
<li><p>@EnableRedisHttpSession这个注解是由spring-session-data-redis提供的，所以在pom.xml文件中添加</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">&lt;dependency&gt;  </div><div class="line">        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;  </div><div class="line">        &lt;artifactId&gt;spring-boot-starter-redis&lt;/artifactId&gt;  </div><div class="line">&lt;/dependency&gt;  </div><div class="line">&lt;dependency&gt;  </div><div class="line">        &lt;groupId&gt;org.springframework.session&lt;/groupId&gt;  </div><div class="line">        &lt;artifactId&gt;spring-session-data-redis&lt;/artifactId&gt;  </div><div class="line">&lt;/dependency&gt;</div></pre></td></tr></table></figure>
</li>
<li><p>application.yml 添加redis配置</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">spring:</div><div class="line">  redis.host: xxxxxx</div><div class="line">  redis.port: xxxx</div><div class="line">  redis.password: xxxx</div></pre></td></tr></table></figure>
</li>
<li><p>idea启动项目两个实例<br>4.1 选择“Edit Configurations”，取消“Single instance only”选项<br>4.2 复制springboot 运行配置<br>4.3 在VM options项中填写-Dserver.port=8082，设置这个实例的运行端口为8082</p>
</li>
</ol>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.codr.top/2018/06/Java/java中对象克隆/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="qingsong">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="青松的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/06/Java/java中对象克隆/" itemprop="url">java中对象克隆</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-13T07:39:47+08:00">
                2018-06-13
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/java/" itemprop="url" rel="index">
                    <span itemprop="name">java</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/06/Java/java中对象克隆/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2018/06/Java/java中对象克隆/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2018/06/Java/java中对象克隆/" class="leancloud_visitors" data-flag-title="java中对象克隆">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  340
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  1
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="浅克隆"><a href="#浅克隆" class="headerlink" title="浅克隆"></a>浅克隆</h2><p>在Java语言中，所有的Java类都继承自java.lang.Object。事实上，Object类提供一个clone()方法，可以将一个Java对象复制一份。因此在Java中可以直接使用Object提供的clone()方法来实现对象的克隆。需要注意的是能够实现克隆的类必须实现接口Cloneable。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">Object object = null;</div><div class="line">try &#123;</div><div class="line">　　　object = super.clone();</div><div class="line">&#125; catch (CloneNotSupportedException exception) &#123;</div><div class="line">　　　System.err.println(&quot;Not support cloneable&quot;);</div><div class="line">&#125;</div><div class="line">return (Prototype )object;</div></pre></td></tr></table></figure></p>
<h2 id="深克隆"><a href="#深克隆" class="headerlink" title="深克隆"></a>深克隆</h2><p>在Java语言中，如果需要实现深克隆，可以通过序列化(Serialization)等方式来实现。序列化就是将对象写到流的过程，写到流中的对象是原有对象的一个拷贝，而原对象仍然存在于内存中。通过序列化实现的拷贝不仅可以复制对象本身，而且可以复制其引用的成员对象，因此通过序列化将对象写到一个流中，再从流里将其读出来，可以实现深克隆。需要注意的是能够实现序列化的对象其类必须实现Serializable接口，否则无法实现序列化操作。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">//将对象写入流中</div><div class="line">ByteArrayOutputStream bao=new  ByteArrayOutputStream();</div><div class="line">ObjectOutputStream oos=new  ObjectOutputStream(bao);</div><div class="line">oos.writeObject(this);</div><div class="line"></div><div class="line">//将对象从流中取出</div><div class="line">ByteArrayInputStream bis=new  ByteArrayInputStream(bao.toByteArray());</div><div class="line">ObjectInputStream ois=new  ObjectInputStream(bis);</div><div class="line">return  (WeeklyLog)ois.readObject();</div></pre></td></tr></table></figure></p>
<h2 id="资料"><a href="#资料" class="headerlink" title="资料"></a>资料</h2><p>原型模式 <a href="https://blog.csdn.net/lovelion/article/details/7424623" target="_blank" rel="external">https://blog.csdn.net/lovelion/article/details/7424623</a></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.codr.top/2018/06/工具/git升级版本/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="qingsong">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="青松的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/06/工具/git升级版本/" itemprop="url">git升级版本</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-04T18:59:07+08:00">
                2018-06-04
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/git/" itemprop="url" rel="index">
                    <span itemprop="name">git</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/06/工具/git升级版本/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2018/06/工具/git升级版本/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2018/06/工具/git升级版本/" class="leancloud_visitors" data-flag-title="git升级版本">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  287
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  2
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>在使用git pull、git push、git clone的时候，会报如下的错误：<br>error: while accessing <a href="https://github.com/Yelp/elastalert.git/info/refs" target="_blank" rel="external">https://github.com/Yelp/elastalert.git/info/refs</a> fatal: HTTP request failed<br>这个一般是由于服务器本身自带的git版本过低造成的：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">git --version</div><div class="line">git version 1.7.1</div></pre></td></tr></table></figure></p>
<p>git版本升级<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line">0）安装依赖软件</div><div class="line">[root@uatjenkins01 ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc</div><div class="line">[root@uatjenkins01 ~]# yum install  gcc perl-ExtUtils-MakeMaker</div><div class="line"> </div><div class="line">1）卸载系统自带的底版本git（1.7.1）</div><div class="line">[root@uatjenkins01 ~]# git --version</div><div class="line">git version 1.7.1</div><div class="line">[root@uatjenkins01 ~]# yum remove git</div><div class="line">  </div><div class="line">2）编译安装最新的git版本</div><div class="line">[root@uatjenkins01 ~]# cd /usr/local/src/</div><div class="line">[root@uatjenkins01 src]# wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.17.1.tar.gz</div><div class="line">[root@uatjenkins01 src]# tar -vxf git-2.17.1.tar.xz</div><div class="line">[root@uatjenkins01 src]# cd git-2.17.1</div><div class="line">[root@uatjenkins01 git-2.17.1]# make prefix=/usr/local/git all</div><div class="line">[root@uatjenkins01 git-2.17.1]# make prefix=/usr/local/git install</div><div class="line">[root@uatjenkins01 git-2.17.1]# echo &quot;export PATH=$PATH:/usr/local/git/bin&quot; &gt;&gt; /etc/profile</div><div class="line">[root@uatjenkins01 git-2.17.1]# source /etc/profile</div><div class="line">  </div><div class="line">[root@uatjenkins01 ~]# git --version</div><div class="line">git version 2.17.1</div><div class="line">  </div><div class="line">======================================================================</div><div class="line">如果是非root用户使用git，则需要配置下该用户下的环境变量</div><div class="line">[app@uatjenkins01 ~]$ echo &quot;export PATH=$PATH:/usr/local/git/bin&quot; &gt;&gt; ~/.bashrc</div><div class="line">[app@uatjenkins01 ~]$ source ~/.bashrc</div><div class="line">[app@uatjenkins01 ~]$ git --version</div><div class="line">git version 2.17.1</div></pre></td></tr></table></figure></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.codr.top/2018/06/ELK/EFK-日志报警/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="qingsong">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="青松的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/06/ELK/EFK-日志报警/" itemprop="url">EFK-日志报警</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-04T17:43:41+08:00">
                2018-06-04
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/ELK/" itemprop="url" rel="index">
                    <span itemprop="name">ELK</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/06/ELK/EFK-日志报警/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2018/06/ELK/EFK-日志报警/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2018/06/ELK/EFK-日志报警/" class="leancloud_visitors" data-flag-title="EFK-日志报警">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  828
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  4
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="Elastalert-安装"><a href="#Elastalert-安装" class="headerlink" title="Elastalert 安装"></a>Elastalert 安装</h2><p>下载 elastalert 源码<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">git clone https://github.com/Yelp/elastalert.git</div><div class="line">cd elastalert</div><div class="line">python setup.py install</div><div class="line">pip install -r requirements.txt</div></pre></td></tr></table></figure></p>
<p>安装完后，会在 /usr/local/bin/ 下生成4个elastalert命令<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">/usr/local/bin/elastalert </div><div class="line">/usr/local/bin/elastalert-create-index  </div><div class="line">/usr/local/bin/elastalert-rule-from-kibana  </div><div class="line">/usr/local/bin/elastalert-test-rule</div></pre></td></tr></table></figure></p>
<p>elastalert-create-index 这个命令会在elasticsearch创建索引，这不是必须的步骤，但是强烈建议创建。因为对于，审计，测试很有用，并且重启elastalert不影响计数和发送alert,默认情况下，创建的索引叫 elastalert_status</p>
<h2 id="Elastalert-配置"><a href="#Elastalert-配置" class="headerlink" title="Elastalert 配置"></a>Elastalert 配置</h2><h2 id="配置文件config-yaml"><a href="#配置文件config-yaml" class="headerlink" title="配置文件config.yaml"></a>配置文件config.yaml</h2><p>/mydata/elk/elastalert/config.yaml</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line"># 规则文件夹</div><div class="line">rules_folder: my_rules</div><div class="line"></div><div class="line"># 查询Elasticsearch时间间隔</div><div class="line">run_every:</div><div class="line">  minutes: 1</div><div class="line"></div><div class="line"># ElastAlert缓存结果时间</div><div class="line">buffer_time:</div><div class="line">  minutes: 15</div><div class="line"></div><div class="line"># Elasticsearch hostname</div><div class="line">es_host: 127.0.0.1</div><div class="line">es_port: 9200</div><div class="line"></div><div class="line"># elasticsearch中的索引名</div><div class="line">writeback_index: elastalert_status</div><div class="line"></div><div class="line"># 发送失败重试时间间隔</div><div class="line">alert_time_limit:</div><div class="line">  days: 2</div><div class="line"></div><div class="line"># 邮箱发送配置</div><div class="line">smtp_host: smtp.exmail.qq.com</div><div class="line">smtp_port: 465</div><div class="line">smtp_ssl: true</div><div class="line">smtp_auth_file: /mydata/elk/elastalert/email_auth.yaml</div><div class="line">from_addr: xxx@xxx.cn</div></pre></td></tr></table></figure>
<h2 id="规则-example-rules"><a href="#规则-example-rules" class="headerlink" title="规则 example_rules"></a>规则 example_rules</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line"># 规则名，需要唯一</div><div class="line">name: pay error frequency rule</div><div class="line"></div><div class="line"># 数据验证方式</div><div class="line">type: frequency</div><div class="line"></div><div class="line"># 从某类索引里读取数据</div><div class="line">index: filebeat-*</div><div class="line"></div><div class="line"># 在时间间隔内匹配多少次触发报警</div><div class="line">num_events: 1</div><div class="line"># 时间间隔</div><div class="line">timeframe:</div><div class="line">  minutes: 1</div><div class="line"></div><div class="line"># ES请求的过滤条件</div><div class="line">filter:</div><div class="line">- query:</div><div class="line">    query_string:</div><div class="line">        query: &apos;source:&quot;/mydata/release/fs-pay/logs/error.log&quot; AND  message:ERROR&apos;</div><div class="line"># 报警渠道</div><div class="line">alert:</div><div class="line">- &quot;email&quot;</div><div class="line">email:</div><div class="line">- &quot;xxxx@xxx.cn&quot;</div></pre></td></tr></table></figure>
<p>自定义邮件内容可以配置 alert_text和alert_text_args</p>
<p>控制报警风暴，减少重复告警的频率<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"># 用来区分报警，跟 realert 配合使用，在这里意味着，</div><div class="line"># 5 分钟内如果有重复报警，那么当 name 不同时，会当做不同的报警处理，可以是数组</div><div class="line">query_key:</div><div class="line"> - name</div><div class="line"></div><div class="line"># 5 分钟内相同的报警不会重复发送</div><div class="line">realert:</div><div class="line"> minutes: 5</div><div class="line"></div><div class="line"># 指数级扩大 realert 时间，中间如果有报警，</div><div class="line"># 则按照 5 -&gt; 10 -&gt; 20 -&gt; 40 -&gt; 60 不断增大报警时间到制定的最大时间，</div><div class="line"># 如果之后报警减少，则会慢慢恢复原始 realert 时间</div><div class="line">exponential_realert:</div><div class="line"> hours: 1</div></pre></td></tr></table></figure></p>
<h3 id="ruletype"><a href="#ruletype" class="headerlink" title="ruletype"></a>ruletype</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">any：只要有匹配就报警；</div><div class="line"></div><div class="line">blacklist：compare_key字段的内容匹配上 blacklist数组里任意内容；</div><div class="line"></div><div class="line">whitelist：compare_key字段的内容一个都没能匹配上whitelist数组里内容；</div><div class="line"></div><div class="line">change：在相同query_key条件下，compare_key字段的内容，在 timeframe范围内 发送变化；</div><div class="line"></div><div class="line">frequency：在相同 query_key条件下，timeframe 范围内有num_events个被过滤出 来的异常；</div><div class="line"></div><div class="line">spike：在相同query_key条件下，前后两个timeframe范围内数据量相差比例超过spike_height。其中可以通过spike_type设置具体涨跌方向是- up,down,both 。还可以通过threshold_ref设置要求上一个周期数据量的下限，threshold_cur设置要求当前周期数据量的下限，如果数据量不到下限，也不触发；</div><div class="line"></div><div class="line">flatline：timeframe 范围内，数据量小于threshold 阈值；</div><div class="line"></div><div class="line">new_term：fields字段新出现之前terms_window_size(默认30天)范围内最多的terms_size (默认50)个结果以外的数据；</div><div class="line"></div><div class="line">cardinality：在相同 query_key条件下，timeframe范围内cardinality_field的值超过 max_cardinality 或者低于min_cardinality</div></pre></td></tr></table></figure>
<h2 id="启动"><a href="#启动" class="headerlink" title="启动"></a>启动</h2><p>启动elastalert服务，监听elasticsearch<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">python -m elastalert.elastalert --verbose</div><div class="line">python -m elastalert.elastalert --verbose --rule example_rules/example_test.yaml</div><div class="line"></div><div class="line">后台运行</div><div class="line">nohup python -m elastalert.elastalert --verbose  &gt;/dev/null 2&gt;&amp;1 &amp;</div><div class="line">指定配置文件</div><div class="line">nohup python -m elastalert.elastalert --verbose --rule example_rules/example_test.yaml &gt;/dev/null 2&gt;&amp;1 &amp;</div></pre></td></tr></table></figure></p>
<h2 id="资料"><a href="#资料" class="headerlink" title="资料"></a>资料</h2><p><a href="https://elastalert.readthedocs.io/en/latest/" target="_blank" rel="external">https://elastalert.readthedocs.io/en/latest/</a><br><a href="https://www.ctolib.com/docs/sfile/ELKstack-guide-cn/elasticsearch/other/elastalert.html" target="_blank" rel="external">https://www.ctolib.com/docs/sfile/ELKstack-guide-cn/elasticsearch/other/elastalert.html</a><br><a href="https://blog.xizhibei.me/2017/11/19/alerting-with-elastalert/" target="_blank" rel="external">https://blog.xizhibei.me/2017/11/19/alerting-with-elastalert/</a><br><a href="http://www.freebuf.com/articles/web/160254.html" target="_blank" rel="external">http://www.freebuf.com/articles/web/160254.html</a><br><a href="http://www.xiaot123.com/post/elk_filebeat1" target="_blank" rel="external">http://www.xiaot123.com/post/elk_filebeat1</a></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.codr.top/2018/06/spring家族/SpringBoot接收时间参数/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="qingsong">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="青松的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/06/spring家族/SpringBoot接收时间参数/" itemprop="url">SpringBoot接收时间参数</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-01T11:44:24+08:00">
                2018-06-01
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/SpringBoot/" itemprop="url" rel="index">
                    <span itemprop="name">SpringBoot</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/06/spring家族/SpringBoot接收时间参数/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2018/06/spring家族/SpringBoot接收时间参数/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2018/06/spring家族/SpringBoot接收时间参数/" class="leancloud_visitors" data-flag-title="SpringBoot接收时间参数">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  361
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  2
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="需求"><a href="#需求" class="headerlink" title="需求"></a>需求</h2><p>服务端需要使用实体类属性字段接收时间，java.util.Date类型的属性字段。</p>
<h2 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h2><p>请求数据时间格式为：”yyyy-MM-dd HH:mm:ss” 字符串<br>报错<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line">    &quot;timestamp&quot;: 1527824946500,</div><div class="line">    &quot;status&quot;: 400,</div><div class="line">    &quot;error&quot;: &quot;Bad Request&quot;,</div><div class="line">    &quot;exception&quot;: &quot;org.springframework.http.converter.HttpMessageNotReadableException&quot;,</div><div class="line">    &quot;message&quot;: &quot;JSON parse error: Can not deserialize value of type java.util.Date from String \&quot;2018-06-01 11:33:55\&quot;: not a valid representation (error: Failed to parse Date value &apos;2018-06-01 11:33:55&apos;: Can not parse date \&quot;2018-06-01 11:33:55\&quot;: while it seems to fit format &apos;yyyy-MM-dd&apos;T&apos;HH:mm:ss.SSS&apos;, parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not deserialize value of type java.util.Date from String \&quot;2018-06-01 11:33:55\&quot;: not a valid representation (error: Failed to parse Date value &apos;2018-06-01 11:33:55&apos;: Can not parse date \&quot;2018-06-01 11:33:55\&quot;: while it seems to fit format &apos;yyyy-MM-dd&apos;T&apos;HH:mm:ss.SSS&apos;, parsing fails (leniency? null))\n at [Source: java.io.PushbackInputStream@73f25959; line: 1, column: 228] (through reference chain: cn.xxx[\&quot;rightsEndTime\&quot;])&quot;,</div><div class="line">    &quot;path&quot;: &quot;/grouppurchase/commodity/add&quot;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<ol>
<li>Springboot使用的默认json解析框架是jackjson框架</li>
<li>jackjson解析框架在解析实体类里面是date数据类型的数据时的默认格式是：UTC类型，即yyyy-MM-dd’T’HH:mm:ss.SSS 并且默认为+8时区，即时间基础上加8小时</li>
</ol>
<h2 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h2><p>实体Date类型的字段上使用@JsonFormat注解格式化日期<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">@JsonFormat(locale=&quot;zh&quot;, timezone=&quot;GMT+8&quot;, pattern=&quot;yyyy-MM-dd HH:mm:ss&quot;)</div></pre></td></tr></table></figure></p>
<p>取消timestamps形式<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);</div></pre></td></tr></table></figure></p>
<p>fastjson解法方法<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">@JsonFormat(shape=JsonFormat.Shape.STRING, pattern=&quot;yyyy-MM-dd HH:mm:ss&quot;)</div></pre></td></tr></table></figure></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.codr.top/2018/05/Java/java版本升级特性/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="qingsong">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="青松的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2018/05/Java/java版本升级特性/" itemprop="url">java版本升级特性</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-05-31T14:59:55+08:00">
                2018-05-31
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/java/" itemprop="url" rel="index">
                    <span itemprop="name">java</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/05/Java/java版本升级特性/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2018/05/Java/java版本升级特性/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2018/05/Java/java版本升级特性/" class="leancloud_visitors" data-flag-title="java版本升级特性">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  1,602
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  8
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="相关名词"><a href="#相关名词" class="headerlink" title="相关名词"></a>相关名词</h2><p>JUG：Java User Groups（Java用户群）<br>JCP：Java Community Process，一个促进Java发展的国际组织，主要负责JSR的制定，OpenJDK的开发。其中JUG属于JCP。<br>EC：Executive Committee，是JCP中的执行委员会，是选举产生的。<br>JEP（JDK Enhancement Proposal，JDK改进提案，JDK增强建议），来源于JCP社区，但不一定被采纳。<br>JSR：Java Specification Requests（Java规范请求），JSR是有状态的，并不是所有的JSR都有效，所以在看JSR时需要先看下状态是否有效。Java的各个版本的语言规范和虚拟机规范都是JSR范畴里的，JSR的生效由Expert Group（专家组）商讨制定并由EC投票确立。JSR的确立是有一个具体流程规范的，不过并不是所有的JSR都会在JDK里实现的。<br>JSR专家组（Expert Group）：从JCP里选出的对应领域有威望的个人（其实背后代表的是所属公司），负责制定和修改JSR。<br>Java语言规范：其实已经包括在JSR里，细分开是因为只是语言层面的，不涉及跨平台的JVM的细节，所以想要详细了解Java语法的可以仔细研读下。<br>JVM规范：这里主要描述虚拟机的实现规范，包括指令集及其作用、虚拟机内存模型、类文件描述、编译、链接、加载、初始化等步聚描述，想要了解虚拟机具体是怎么工作的可以仔细研读下，不过规范不涉及实现，目前虚拟机的实现也有很多种，HotSpot是OpenJDK里的，想要了解实现细节的可以下载HotSpot源码看下。</p>
<h2 id="Java-11-新特性"><a href="#Java-11-新特性" class="headerlink" title="Java 11 新特性"></a>Java 11 新特性</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">官网公开的 17 个 JEP（JDK Enhancement Proposal 特性增强提议）：</div><div class="line">181: Nest-Based Access Control（基于嵌套的访问控制）</div><div class="line">309: Dynamic Class-File Constants（动态的类文件常量）</div><div class="line">315: Improve Aarch64 Intrinsics（改进 Aarch64 Intrinsics）</div><div class="line">318: Epsilon: A No-Op Garbage Collector（Epsilon 垃圾回收器，又被称为&quot;No-Op（无操作）&quot;回收器）</div><div class="line">320: Remove the Java EE and CORBA Modules（移除 Java EE 和 CORBA 模块，JavaFX 也已被移除）</div><div class="line">321: HTTP Client (Standard)</div><div class="line">323: Local-Variable Syntax for Lambda Parameters（用于 Lambda 参数的局部变量语法）</div><div class="line">324: Key Agreement with Curve25519 and Curve448（采用 Curve25519 和 Curve448 算法实现的密钥协议）</div><div class="line">327: Unicode 10</div><div class="line">328: Flight Recorder（飞行记录仪）</div><div class="line">329: ChaCha20 and Poly1305 Cryptographic Algorithms（实现 ChaCha20 和 Poly1305 加密算法）</div><div class="line">330: Launch Single-File Source-Code Programs（启动单个 Java 源代码文件的程序）</div><div class="line">331: Low-Overhead Heap Profiling（低开销的堆分配采样方法）</div><div class="line">332: Transport Layer Security (TLS) 1.3（对 TLS 1.3 的支持）</div><div class="line">333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)（ZGC：可伸缩的低延迟垃圾回收器，处于实验性阶段）</div><div class="line">335: Deprecate the Nashorn JavaScript Engine（弃用 Nashorn JavaScript 引擎）</div><div class="line">336: Deprecate the Pack200 Tools and API（弃用 Pack200 工具及其 API）</div></pre></td></tr></table></figure>
<h2 id="java-10"><a href="#java-10" class="headerlink" title="java 10"></a>java 10</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">286：本地变量类型推断</div><div class="line">296：统一JDK仓库</div><div class="line">304：垃圾回收器接口</div><div class="line">307：G1的并行Full GC</div><div class="line">310：应用程序类数据共享</div><div class="line">312：ThreadLocal握手机制</div></pre></td></tr></table></figure>
<h2 id="java-9"><a href="#java-9" class="headerlink" title="java 9"></a>java 9</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">Java 平台级模块系统</div><div class="line">Linking</div><div class="line">JShell : 交互式 Java REPL</div><div class="line">改进的 Javadoc</div><div class="line">集合工厂方法</div><div class="line">改进的 Stream API</div><div class="line">私有接口方法</div><div class="line">HTTP/2</div><div class="line">多版本兼容 JAR</div></pre></td></tr></table></figure>
<p>前辍说明：U:修改，A:新增，D:废弃，M:模块化，S:安全<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div></pre></td><td class="code"><pre><div class="line">U  102: Process API Updates</div><div class="line">A  110: HTTP 2 Client</div><div class="line">U  143: Improve Contended Locking</div><div class="line">U  158: Unified JVM Logging</div><div class="line">U  165: Compiler Control</div><div class="line">U  193: Variable Handles</div><div class="line">U  197: Segmented Code Cache</div><div class="line">U  199: Smart Java Compilation, Phase Two</div><div class="line">AM 200: The Modular JDK</div><div class="line">AM 201: Modular Source Code</div><div class="line">A  211: Elide Deprecation Warnings on Import Statements</div><div class="line">A  212: Resolve Lint and Doclint Warnings</div><div class="line">U  213: Milling Project Coin</div><div class="line">D  214: Remove GC Combinations Deprecated in JDK 8</div><div class="line">A  215: Tiered Attribution for javac</div><div class="line">U  216: Process Import Statements Correctly</div><div class="line">U  217: Annotations Pipeline 2.0</div><div class="line">A  219: Datagram Transport Layer Security (DTLS)</div><div class="line">AM 220: Modular Run-Time Images</div><div class="line">A  221: Simplified Doclet API</div><div class="line">A  222: jshell: The Java Shell (Read-Eval-Print Loop)</div><div class="line">A  223: New Version-String Scheme</div><div class="line">U  224: HTML5 Javadoc</div><div class="line">A  225: Javadoc Search</div><div class="line">A  226: UTF-8 Property Files</div><div class="line">A  227: Unicode 7.0</div><div class="line">A  228: Add More Diagnostic Commands</div><div class="line">US 229: Create PKCS12 Keystores by Default</div><div class="line">D  231: Remove Launch-Time JRE Version Selection</div><div class="line">U  232: Improve Secure Application Performance</div><div class="line">A  233: Generate Run-Time Compiler Tests Automatically</div><div class="line">A  235: Test Class-File Attributes Generated by javac</div><div class="line">A  236: Parser API for Nashorn</div><div class="line">A  237: Linux/AArch64 Port</div><div class="line">U  238: Multi-Release JAR Files</div><div class="line">D  240: Remove the JVM TI hprof Agent</div><div class="line">D  241: Remove the jhat Tool</div><div class="line">A  243: Java-Level JVM Compiler Interface</div><div class="line">US 244: TLS Application-Layer Protocol Negotiation Extension</div><div class="line">U  245: Validate JVM Command-Line Flag Arguments</div><div class="line">US 246: Leverage CPU Instructions for GHASH and RSA</div><div class="line">U  247: Compile for Older Platform Versions</div><div class="line">U  248: Make G1 the Default Garbage Collector</div><div class="line">AS 249: OCSP Stapling for TLS</div><div class="line">U  250: Store Interned Strings in CDS Archives</div><div class="line">A  251: Multi-Resolution Images</div><div class="line">U  252: Use CLDR Locale Data by Default</div><div class="line">A  253: Prepare JavaFX UI Controls &amp; CSS APIs for Modularization</div><div class="line">U  254: Compact Strings</div><div class="line">U  255: Merge Selected Xerces 2.11.0 Updates into JAXP</div><div class="line">U  256: BeanInfo Annotations</div><div class="line">U  257: Update JavaFX/Media to Newer Version of GStreamer</div><div class="line">U  258: HarfBuzz Font-Layout Engine</div><div class="line">A  259: Stack-Walking API</div><div class="line">UM 260: Encapsulate Most Internal APIs</div><div class="line">AM 261: Module System</div><div class="line">U  262: TIFF Image I/O</div><div class="line">A  263: HiDPI Graphics on Windows and Linux</div><div class="line">A  264: Platform Logging API and Service</div><div class="line">U  265: Marlin Graphics Renderer</div><div class="line">U  266: More Concurrency Updates</div><div class="line">A  267: Unicode 8.0</div><div class="line">A  268: XML Catalogs</div><div class="line">A  269: Convenience Factory Methods for Collections</div><div class="line">U  270: Reserved Stack Areas for Critical Sections</div><div class="line">U  271: Unified GC Logging</div><div class="line">A  272: Platform-Specific Desktop Features</div><div class="line">A  273: DRBG-Based SecureRandom Implementations</div><div class="line">U  274: Enhanced Method Handles</div><div class="line">AM 275: Modular Java Application Packaging</div><div class="line">AM 276: Dynamic Linking of Language-Defined Object Models</div><div class="line">U  277: Enhanced Deprecation</div><div class="line">A  278: Additional Tests for Humongous Objects in G1</div><div class="line">U  279: Improve Test-Failure Troubleshooting</div><div class="line">U  280: Indify String Concatenation</div><div class="line">A  281: HotSpot C++ Unit-Test Framework</div><div class="line">AM 282: jlink: The Java Linker</div><div class="line">A  283: Enable GTK 3 on Linux</div><div class="line">U  284: New HotSpot Build System</div><div class="line">A  285: Spin-Wait Hints</div><div class="line">AS 287: SHA-3 Hash Algorithms</div><div class="line">DS 288: Disable SHA-1 Certificates</div><div class="line">D  289: Deprecate the Applet API</div><div class="line">AS 290: Filter Incoming Serialization Data</div><div class="line">D  291: Deprecate the Concurrent Mark Sweep (CMS) Garbage Collector</div><div class="line">A  292: Implement Selected ECMAScript 6 Features in Nashorn</div><div class="line">A  294: Linux/s390x Port</div><div class="line">A  295: Ahead-of-Time Compilation</div><div class="line">U  297: Unified arm32/arm64 Port</div><div class="line">D  298: Remove Demos and Samples</div><div class="line">U  299: Reorganize Documentation</div></pre></td></tr></table></figure></p>
<h2 id="java8"><a href="#java8" class="headerlink" title="java8"></a>java8</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">允许在接口中有默认方法实现</div><div class="line">Lambda表达式</div><div class="line">函数式接口</div><div class="line">方法和构造函数引用</div><div class="line">Lambda的范围</div><div class="line">内置函数式接口</div><div class="line">Streams</div><div class="line">Parallel Streams</div><div class="line">Map</div><div class="line">时间日期API</div><div class="line">Annotations</div></pre></td></tr></table></figure>
<h2 id="java7"><a href="#java7" class="headerlink" title="java7"></a>java7</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">switch语句块中允许以字符串作为分支条件；</div><div class="line">在创建泛型对象时应用类型推断；</div><div class="line">在一个语句块中捕获多种异常；</div><div class="line">支持动态语言；</div><div class="line">支持try-with-resources；</div><div class="line">引入Java NIO.2开发包；</div><div class="line">数值类型可以用2进制字符串表示，并且可以在字符串表示中添加下划线；</div><div class="line">try-with-resources(新语法)。定义在try-with-resources 声明里，无论try语句正常还是异常的结束，</div><div class="line">   它都会自动的关掉</div></pre></td></tr></table></figure>
<h2 id="java6"><a href="#java6" class="headerlink" title="java6"></a>java6</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">支持脚本语言；</div><div class="line">引入JDBC 4.0 API；</div><div class="line">引入Java Compiler API；</div><div class="line">可插拔注解；</div><div class="line">增加对Native PKI(Public Key Infrastructure)、Java GSS(Generic Security Service)、Kerberos和LDAP(Lightweight Directory Access Protocol)的支持；</div><div class="line">继承Web Services；</div><div class="line">做了很多优化。</div></pre></td></tr></table></figure>
<h2 id="java5"><a href="#java5" class="headerlink" title="java5"></a>java5</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">引入泛型；</div><div class="line">增强循环，可以使用迭代方式；</div><div class="line">自动装箱与自动拆箱；</div><div class="line">类型安全的枚举；</div><div class="line">可变参数；</div><div class="line">静态引入；</div><div class="line">元数据（注解）；</div><div class="line">引入Instrumentation。</div></pre></td></tr></table></figure>
<h2 id="资料"><a href="#资料" class="headerlink" title="资料"></a>资料</h2><p><a href="https://juejin.im/entry/5aa234b35188255570059b78" target="_blank" rel="external">https://juejin.im/entry/5aa234b35188255570059b78</a><br><a href="https://segmentfault.com/a/1190000004417830" target="_blank" rel="external">https://segmentfault.com/a/1190000004417830</a></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><span class="space">&hellip;</span><a class="page-number" href="/page/8/">8</a><a class="extend next" rel="next" href="/page/2/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel sidebar-panel-active">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.jpg"
               alt="qingsong" />
          <p class="site-author-name" itemprop="name">qingsong</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">71</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">27</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">52</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hanqingsong" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                    
                      GitHub
                    
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-block">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.zhangxinxu.com/" title="张鑫旭" target="_blank">张鑫旭</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://toutiao.io/" title="开发者头条" target="_blank">开发者头条</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://juejin.im" title="掘金" target="_blank">掘金</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">qingsong</span>
</div>

<div class="powered-by">
  <i class="fa fa-user-md"></i>
  <span id="busuanzi_container_site_uv">
 	 本站访客数:<span id="busuanzi_value_site_uv"></span>
  </span>
  <span id="busuanzi_container_site_pv">
     本站总访问量<span id="busuanzi_value_site_pv"></span>次
 </span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  
    <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>

  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  

    
      <script id="dsq-count-scr" src="https://http-codr-top.disqus.com/count.js" async></script>
    

    

  




	





  








  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("pEP7QBpxoOqTMKIGmwLw4KSA-gzGzoHsz", "iymUJSFCUUHdCVewPQfwJNjX");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  

  

  

</body>
</html>
